package org.jeecg.modules.qyxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
import org.jeecg.modules.qyxx.entity.BgFpHzNdWdxSxyyclcp;
import org.jeecg.modules.qyxx.entity.req.BgNsrjbxxReq;
import org.jeecg.modules.qyxx.mapper.BgFpHzNdWdxSxyyclcpMapper;
import org.jeecg.modules.qyxx.service.IBgFpHzNdWdxSxyyclcpService;
import org.jeecg.modules.qyxx.service.IBgSjmkjgOrderService;
import org.jeecg.modules.qyxx.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 上下游原材料和产品稳定性汇总数据
 * @Author: jeecg-boot
 * @Date:   2022-05-09
 * @Version: V1.0
 */
@Service
public class BgFpHzNdWdxSxyyclcpServiceImpl extends MppServiceImpl<BgFpHzNdWdxSxyyclcpMapper, BgFpHzNdWdxSxyyclcp> implements IBgFpHzNdWdxSxyyclcpService {
    @Autowired
    private IBgSjmkjgOrderService bgSjmkjgOrderService;

    @Override
    public List<BgFpHzNdWdxSxyyclcp> getTop5YclCpWdxZb(BgNsrjbxxReq req) {
        DateUtils utils = DateUtils.getInstance();
        // String year = bgSjmkjgOrderService.getNewByDjxh(req.getDjxh());
        String year = utils.getYearToStr(req.getJssj());
        List<String> tjnds = DateUtils.getInstance().nearlyThreeYears(req.getKssj(), req.getJssj());
        List<BgFpHzNdWdxSxyyclcp> list = baseMapper.getTop5YclCpWdxZb(req.getDjxh(), String.join(",", tjnds));
        /*LambdaQueryWrapper<BgFpHzNdWdxSxyyclcp> wrapper = Wrappers.lambdaQuery(BgFpHzNdWdxSxyyclcp.class);
        wrapper.eq(BgFpHzNdWdxSxyyclcp::getDjxh,req.getDjxh()).in(BgFpHzNdWdxSxyyclcp::getTjnd,tjnds);
        List<BgFpHzNdWdxSxyyclcp> list = super.list(wrapper);*/
        for (BgFpHzNdWdxSxyyclcp bgFpHzNdWdxSxyyclcp : list) {
            if (year.equals(bgFpHzNdWdxSxyyclcp.getTjnd())) {
               // String month = bgSjmkjgOrderService.getNewMonthByDjxh(req.getDjxh());
                String month = utils.getMonthToStr(req.getJssj());
                String newMonth = month.substring(month.length() - 2);
                bgFpHzNdWdxSxyyclcp.setTjnd(year + "年(" + newMonth + "月)");
            } else {
                bgFpHzNdWdxSxyyclcp.setTjnd(bgFpHzNdWdxSxyyclcp.getTjnd() + "年");
            }
        }
        return list;
    }
}
